package com.leTest.eduService.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leTest.R;
import com.leTest.eduService.entity.CourseEntity;
import com.leTest.eduService.entity.chapter.ChapterVo;
import com.leTest.eduService.entity.frontVo.CourseFrontVo;
import com.leTest.eduService.entity.frontVo.CourseWebVo;
import com.leTest.eduService.service.ChapterService;
import com.leTest.eduService.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduService/coursefront")
@CrossOrigin
public class CourseFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private ChapterService chapterService;


    //1.课程条件查询带分页
    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseList(@PathVariable long page,
                                @PathVariable long limit,
                                @RequestBody(required = false) CourseFrontVo courseFrontVo) {
        Page<CourseEntity> pageCourse = new Page<>(page, limit);
        Map<String, Object> map = courseService.getCourseFrontList(pageCourse, courseFrontVo);
        return R.ok().data(map);
    }

    //2.查询课程详情
    @GetMapping("getFrontCourseInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId) {
        //根据课程id查询课程信息(手写sql语句来实现)
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(courseId);

        //根据课程id查询课程章节和小节
        List<ChapterVo> chapterVideoList = chapterService.getChapterVideoByCourseId(courseId);

        return R.ok().data("courseWebVo", courseWebVo).data("chapterVideoList", chapterVideoList);
    }

}

